package com.huat.config;

import com.huat.mapper.UserMapper;
import com.huat.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSenderImpl;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class ScheduledUser {

    @Autowired
    JavaMailSenderImpl mailSender;
    @Autowired
    UserMapper userMapper;
    //cron表达式
    @Scheduled(cron = "0 0 7,22 * * ?")
    public void informUser() {
        List<User> userList = userMapper.findAllUser();
        for (User user:userList) {
            SimpleMailMessage simpleMailMessage = new SimpleMailMessage();
            simpleMailMessage.setSubject("疫情信息填报提醒");
            simpleMailMessage.setText(user.getUserName()+"同学你好，今日疫情信息开始填报了！");
            simpleMailMessage.setTo(user.getEmail());
            simpleMailMessage.setFrom("1959414401@qq.com");
            mailSender.send(simpleMailMessage);
        }

    }
}
